﻿/*****
 *  Copyright 2011, Kaven Gagné
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

using System.Collections.Generic;
using System.Windows;
using Knowledge.Resources;

namespace Knowledge
{
    public class ButtonsManager
    {
        List<HeaderMenuButton> buttonsList = new List<HeaderMenuButton>();
        public ButtonsManager(MainWindow app)
        {
            // Articles
            buttonsList.Add(app.buttonArticlesDelete);
            buttonsList.Add(app.buttonArticlesRename);
            buttonsList.Add(app.buttonArticlesNewArticle);
            buttonsList.Add(app.buttonArticlesNewFolder);

            // Description
            buttonsList.Add(app.buttonDescriptionCancel);
            buttonsList.Add(app.buttonDescriptionSave);
            buttonsList.Add(app.buttonDescriptionEdit);

            // Links
            buttonsList.Add(app.buttonLinksDelete);
            buttonsList.Add(app.buttonLinksAdd);

            // Files
            buttonsList.Add(app.buttonFilesSaveAs);
            buttonsList.Add(app.buttonFilesDelete);
            buttonsList.Add(app.buttonFilesAdd);
        }


        /***
         * Change States of all Buttons in the order they have been added
         * States:
         *     -1: No Change
         *      0: Visibility=Collapsed, isEnabled=true // Hidden
         *      1: Visibility=Visible, isEnabled=false  // Disabled
         *      2: Visibility=Visible, isEnabled=true   // Enabled
         */
        
        public void changeStates(int[] sFlags)
        {
            int index = 0;
            foreach (HeaderMenuButton but in buttonsList)
            {
                switch (sFlags[index])
                {
                    case 0:
                    {
                        but.IsEnabled = true;
                        but.Visibility = Visibility.Collapsed;
                        break;
                    }
                    case 1:
                    {
                        but.IsEnabled = false;
                        but.Visibility = Visibility.Visible;
                        break;
                    }
                    case 2:
                    {
                        but.IsEnabled = true;
                        but.Visibility = Visibility.Visible;
                        break;
                    }
                    default:
                        break;
                }
                index++;
            }
        }
    }
}
